<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    body{
        margin: 0;
        height: 1500px;
    }
    .dv{
        width: 100px;
        height:100px;
        background: hotpink;
        position: absolute;
        left: 300px;
        top: 300px;

        
    }
    .container{
        width: 600px;
        height: 600px;
        border:3px solid blue;
        position: relative;
        left: 200px;
    }
</style>
<body>
    <div class="container">
        <div class="dv"></div>
        <button id="btn">点击</button>
    </div>
</body>
</html>
<script src='https://code.jquery.com/jquery-3.6.0.min.js'></script>
<script>
    //position 获取元素的偏移值，相对于父元素
    // console.log($(".dv").position()); //{top: 300, left: 300}
    // console.log($(".dv").position().left) //300
    // console.log($(".dv").position().top)  //300
    

    //----------------------------------------

    //offset 获取当前元素基于浏览器的位置 
    //可以进行设置
    // console.log( $(".dv").offset()); //{top: 303, left: 503}
    // console.log($(".dv").offset().left); //503
    // $(".dv").offset({left:100,top:100}) //设置

    //----------------------------------------

    //获取页面被卷去的宽高
    $(window).scrollTop()
    $(window).scrollLeft()

    window.onscroll = function() {
        console.log($(window).scrollTop());
    }

    btn.onclick = function(){
        $(window).scrollTop(300) //传参就是设置 300
    }
  



</script>
